package edu.faytechcc.csc251.gui;

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.*;

/**
 *
 * @author kent
 */
public class StartupWindow extends JFrame
{

    private JButton databaseButton;
    private JButton collectionButton;
    private JButton deckButton;
    private JPanel buttonPanel;
    private LogoPanel logoPanel;

    /**
     * Constructor
     */
    public StartupWindow()
    {
        try {
            UIManager.setLookAndFeel(
                    UIManager.getSystemLookAndFeelClassName());
        } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException ex) {
            Logger.getLogger(StartupWindow.class.getName()).log(Level.SEVERE, null, ex);
        }
        //Set the title
        this.setTitle("Welcome");

        //Close button
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        //Create a BorderLayout manager.
        this.setLayout(new BorderLayout());
        
        //Creat the image icon for the logo
        logoPanel = new LogoPanel();
        this.add(logoPanel, BorderLayout.CENTER);

        //Build the button panel
        this.buildButtonPanel();

        //Add the panel to the window
        this.add(buttonPanel, BorderLayout.SOUTH);
        //Pack and display the window
        this.pack();
        this.setLocationRelativeTo(null);
        this.setVisible(true);
        //this.setResizable(false);
    }

    /**
     * The buildButtonPanel method adds the buttons to a panel.
     */
    private void buildButtonPanel()
    {
        //Create the panels
        buttonPanel = new JPanel(new BorderLayout());
        JPanel temp = new JPanel(new FlowLayout());
        //Create the buttons
        databaseButton = new JButton("MTG Database");
        collectionButton = new JButton("My Collection");
        deckButton = new JButton("DeckViewer");

        databaseButton.addActionListener(new DatabaseButtonListener());
        collectionButton.addActionListener(new CollectionButtonListener());
        deckButton.addActionListener(new DeckButtonListener());

        //Add the buttons to the temp panel then the button panel
        temp.add(databaseButton);
        temp.add(collectionButton);
        buttonPanel.add(temp, BorderLayout.NORTH);
        JPanel temp2 = new JPanel();
        temp2.add(deckButton);
        buttonPanel.add(temp2, BorderLayout.CENTER);
    }

    private class CollectionButtonListener implements ActionListener
    {

        public void actionPerformed(ActionEvent e)
        {
            setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
            CollectionWindow collectionWindow = new CollectionWindow();
            setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
        }
    }

    private class DatabaseButtonListener implements ActionListener
    {

        public void actionPerformed(ActionEvent e)
        {
            setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
            MTGDatabaseWindow databaseWindow = new MTGDatabaseWindow();
            setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
        }
    }

    private class DeckButtonListener implements ActionListener
    {

        public void actionPerformed(ActionEvent e)
        {
            SelectionWindow selectionWindow = new SelectionWindow();
        }
    }
}
